package org.acompanhamento.pages.task;

import java.util.List;

import jmine.tec.report.impl.table.ReportTableBuilder;
import jmine.tec.web.wicket.pages.form.CrudModelPage;
import jmine.tec.web.wicket.pages.form.FormType;

import org.acompanhamento.HelpMessages;
import org.acompanhamento.dao.TaskDAO;
import org.acompanhamento.domain.Task;
import org.apache.wicket.Page;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import bancosys.tec.exception.MessageCreator;
import bancosys.tec.persist.dao.BaseDAOFactory;
import bancosys.tec.security.annotation.Secure;
import bancosys.tec.security.authorization.UrlPermission;

/**
 * 
 * @author icaro.kume
 *
 */
@Secure(id = "GENERIC_TEAM_MEMBER_URL", permissionType = UrlPermission.class)
public class ListTask extends CrudModelPage<TaskFilterVO, Task> {

	@Override
	public Page createNewPage() {
		return new EditTask(new PageParameters(), this);
	}

	@Override
	public List<Task> search(BaseDAOFactory daoFactory) {
		TaskDAO tasKDAO = daoFactory.getDAOByClass(TaskDAO.class);
		return tasKDAO.findBy(this.getModel().getIdentifier(), this.getModel().getDescription(), this.getModel().getSummary(),
				this.getModel().getPoints(), this.getModel().getSprint(), this.getModel().getStatus(),
				this.getModel().getResponsible(), this.getModel().getRecordDate());
	}

	@Override
	protected Page createFormPage(Task task, FormType formType) {
		return new EditTask(this.getPage(), new PageParameters(), task, formType);
	}

	@Override
	protected void addResultTableColumns(ReportTableBuilder<Task> tableBuilder) {
		tableBuilder.addStringColumn("identifier", "Identificador", "identifier");
		tableBuilder.addStringColumn("summary", "Resumo", "summary");
		tableBuilder.addStringColumn("responsible", "Respons��vel", "responsible");
		tableBuilder.addStringColumn("sprint", "Itera����o", "sprint");
		tableBuilder.addNumberColumn("points", "Pontos", "points", 0);
	}

	@Override
	protected TaskFilterVO createModel() {
		return new TaskFilterVO();
	}

	@Override
	protected MessageCreator getHelpTextCreator() {
		return HelpMessages.TASK_LIST;
	}

}
